package util;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;

import primatives.PointND;

import delaunay_triangulation.Point_dt;

public class PointCloudWriter
{
	public static void WriteFile(String filename, ArrayList<Point_dt> points)
	{
		try
		{
			PrintStream out = new PrintStream(new FileOutputStream(filename));
			for (Point_dt p: points)
			{
				out.println(p.x() + " " + p.y() + " " + p.z());	
			}
		    out.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
		System.out.println("Finished writing to " + filename + " ("+points.size()+" points)");
	}
	
	public static void WriteFile_PointND(String filename, ArrayList<PointND> points)
	{
		try
		{
			PrintStream out = new PrintStream(new FileOutputStream(filename));
			out.println("** number of points : "+points.size()+" **");
			for (PointND p: points)
			{
				for (int i = 0; i < p.dimensions-1; i++) out.print(p.get_coord(i) + " ");
				out.println(p.get_coord(p.dimensions-1));
//				if (p.dimensions == 3) out.println(p.get_coord(0) + " " + p.get_coord(1) + " " + p.get_coord(2));
//				if (p.dimensions == 5) out.println(p.get_coord(0) + " " + p.get_coord(1) + " " + p.get_coord(2) + " " + p.get_coord(3) + " " + p.get_coord(4));
			}
			out.println("**end cloud**");
		    out.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		
		System.out.println("Finished writing to " + filename + " ("+points.size()+" points)");
	}
}
